/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ar.edu.unicen.twitter.suggest.backend.recommendation.crawling.RecolectorApi;

import ar.edu.unicen.twitter.suggest.backend.datasources.TwitterFacade;
import ar.edu.unicen.twitter.suggest.backend.recommendation.CompararUsuarios.CompararUsuarios;
import ar.edu.unicen.twitter.suggest.backend.recommendation.CriterioUsuario.CriterioUsuario;
import ar.edu.unicen.twitter.suggest.backend.recommendation.crawling.NivelRecoleccion;
import ar.edu.unicen.twitter.suggest.backend.recommendation.crawling.RecoleccionFactory;
import ar.edu.unicen.twitter.suggest.commons.dtos.Usuario;
import ar.edu.unicen.twitter.suggest.interfaces.exceptions.RejectedException;
import ar.edu.unicen.twitter.suggest.interfaces.exceptions.TwitterException;
import ar.edu.unicen.twitter.suggest.interfaces.exceptions.UserNotFoundException;
import ar.edu.unicen.twitter.suggest.interfaces.exceptions.UserProtectedException;
import java.util.Collection;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Alex
 */
public class RecolecionApiFactory implements RecoleccionFactory {

    TwitterFacade twitterFacade;
    public RecolecionApiFactory(TwitterFacade twitterFacade){
        this.twitterFacade = twitterFacade;
    }
    @Override
    public NivelRecoleccion getNivelRecoleccion(TipoNivel tipoNivel, TipoTransicion tipoTransicion, CriterioUsuario criterio, CompararUsuarios comparador, int maxNivel) {
        if (tipoNivel == TipoNivel.NivelSeguidores) {
            return new NivelSeguidoresApi(criterio, comparador, maxNivel);
        } else if (tipoNivel == TipoNivel.NivelSeguidos) {
            return new NivelSeguidosApi(criterio, comparador, maxNivel);
        } else {
            return null;
        }
    }

    @Override
    public Usuario getUsuario(long id) {
        try {
            return twitterFacade.getUser(id);
        } catch (UserNotFoundException ex) {
            Logger.getLogger(RecolecionApiFactory.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UserProtectedException ex) {
            Logger.getLogger(RecolecionApiFactory.class.getName()).log(Level.SEVERE, null, ex);
        } catch (RejectedException ex) {
            Logger.getLogger(RecolecionApiFactory.class.getName()).log(Level.SEVERE, null, ex);
        } catch (TwitterException ex) {
            Logger.getLogger(RecolecionApiFactory.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    @Override
    public Collection<Usuario> getSeguidos(Usuario u) {
        return u.getFollows();
    }

    @Override
    public Collection<Usuario> getSeguidores(Usuario u) {
        return u.getFollowers();
    }

    @Override
    public Collection<Usuario> verificar(Collection<Usuario> usuarios) {
        return usuarios;
    }

    @Override
    public int getMaxArcos() {
        return twitterFacade.getMaxLinks();
    }

    @Override
    public void setMaxArcos(int maxArcos) {
        twitterFacade.setMaxLinks(maxArcos);
    }

    @Override
    public Collection<Usuario> getAmigos(Usuario u) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
}
